package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.Login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * 根据用户id获取用户信息
	 * @param userId
	 * @return
	 */
	@Operation(summary = "根据用户id获取用户信息")
	@GetMapping("getUserInfoVo/{userId}")
	public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId){
		UserInfoVo userInfoVo=userInfoService.getUserInfoVo(userId);
		return Result.ok(userInfoVo);
	}

	/**
	 * 根据专辑id和付费声音列表查询用户是否已买过此声音
	 * @param albumId
	 * @param trackIdList
	 * @return
	 */
	@TsLogin
	@Operation(summary = "根据专辑id和付费声音列表查询用户是否已买过此声音")
	@PostMapping("/userIsPaidTrack/{albumId}")
	Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable("albumId") Long albumId, @RequestBody List<Long> trackIdList){
		Long userId= AuthContextHolder.getUserId();
		Map<Long, Integer> map = userInfoService.userIsPaidTrack(albumId, trackIdList, userId);
		return Result.ok(map);
	}
}

